package cxydmmszl.chapter09.t149;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * <li style="color: red;">Prob</li>
 * 判断一个点是否在矩形内部
 * <li style="color: green;">Desc</li>
 * 在二维坐标系中，所有的值是 double 类型，那么一个矩形可以由四个点来代表，
 * (x1, y1)为最左的点，(x2, y2)为最上的点，(x3, y3)为最下的点，(x4, y4)为最右的点。
 * 给定 4 个点代表的矩形，再给定一个点(x, y)，判断(x, y)是否在矩形中。
 * <br/><br/>备注：<br/>
 * −2∗10^10⩽xi, yi ,x, y⩽2∗10^10
 * <br/>保证输入的顺序与题目描述相同
 * <li style="color: green;">Input</li>
 * 输入有五行，每行两个整数。
 * 对于前四行，第 i 行的浮点数表示 (Xi, Yi)。
 * 最后一行两个浮点数表示 (x, y)。
 * <li style="color: green;">Output</li>
 * 若(x, y)在矩形中，输出 "Yes"，否则输出 "No"。
 * <li style="color: blue;">Link</li> CD58
 *
 * @author habitplus
 * @since 2021-10-16 10:43
 */
public class Main {
    static final StreamTokenizer st =
            new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static double nextDouble() {
        try {
            st.nextToken();
            return st.nval;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws Exception {
        double x1 = nextDouble();
        double y1 = nextDouble();

        double x2 = nextDouble();
        double y2 = nextDouble();

        double x3 = nextDouble();
        double y3 = nextDouble();

        double x4 = nextDouble();
        double y4 = nextDouble();

        double x = nextDouble();
        double y = nextDouble();

        boolean ans = isInside(x1, y1, x2, y2, x3, y3, x4, y4, x, y);
        System.out.println(ans ? "Yes" : "No");
    }

    private static boolean isInside(double x1, double y1,
                                    double x2, double y2,
                                    double x3, double y3,
                                    double x4, double y4,
                                    double x, double y) {
        if (y1 == y2) {
            // 平行于坐标轴的情况
            return isInside(x1, y1, x4, y4, x, y);
        }

        double l = y4 - y3;
        double k = x4 - x3;
        double s = Math.sqrt(k * k - l * l);
        double sin = l / s;
        double cos = k / s;
        double x1R = cos * x1 + sin * y1;
        double y1R = cos * y1 - sin * x1;
        double x4R = cos * x4 + sin * y4;
        double y4R = cos * y4 - sin * x4;
        double xR = cos * x + sin * y;
        double yR = cos * y - sin * x;
        return isInside(x1R, y1R, x4R, y4R, xR, yR);
    }

    private static boolean isInside(double x1, double y1, double x4, double y4, double x, double y) {
        if (x <= x1 || x >= x4 || y >= y1 || y <= y4) {
            return false;
        }
        return true;
    }
}
